//
//  DrawViewController.m
//  Leisure
//
//  Created by xalo on 16/6/28.
//  Copyright © 2016年 Hero. All rights reserved.
//

#import "DrawViewController.h"

@interface DrawViewController ()<MenuViewControllerDelegate>
@property (nonatomic,strong)MenuViewController *menuVC;       //接收菜单栏
@property (nonatomic,strong)UINavigationController *rightNVC; //右侧视图导航栏控制器
@end

@implementation DrawViewController
//自定义初始化方法，在初始化的时候就直接给上左右控制器
- (instancetype)initWithMenuViewController:(MenuViewController *)menuVC
                       RightViewController:(RightViewController *)rightVC
{
    self = [super init];
    if (self) {
        self.menuVC   = menuVC;
        self.menuVC.delegate = self;
        self.rightNVC = [[UINavigationController alloc]initWithRootViewController:rightVC];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //添加子视图控制器
    [self addChildViewController:self.menuVC];
    [self addChildViewController:self.rightNVC];
    //添加子视图
    [self.view addSubview:self.menuVC.view];
    [self.view addSubview:self.rightNVC.view];
}

//实现协议方法更换右视图
- (void)menuViewControllerDidClickWith:(RightViewController *)VC{

    [UIView animateWithDuration:0.2 animations:^{
        //替换之前先把旧的向右偏移
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
    } completion:^(BOOL finished) {
        //先移除旧的
        [self.rightNVC removeFromParentViewController];
        [self.rightNVC.view removeFromSuperview];
        
        //添加新的
        self.rightNVC = [[UINavigationController alloc]initWithRootViewController:VC];
        [self addChildViewController:self.rightNVC];
        [self.view addSubview:self.rightNVC.view];
        
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
        
        //把新的再偏移回来
        [UIView animateKeyframesWithDuration:0.2 delay:0.1 options:UIViewKeyframeAnimationOptionLayoutSubviews animations:^{
            self.rightNVC.view.frame = self.view.frame;
        } completion:^(BOOL finished) {
            
        }];

    }];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
